<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopActivityOrderTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_activity_order', ['comment' => '活动订单', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('user_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '用户'])
            ->addColumn('activity_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '活动'])
            ->addColumn('activity_title', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '活动标题'])
            ->addColumn('activity_type', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '活动类型'])
            ->addColumn('order_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '订单'])
            ->addColumn('pay_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '金额'])
            ->addColumn('discount_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '优惠金额/赠送金额'])
            ->addColumn('goods_amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '参与商品金额'])
            ->addColumn('goods_ids', 'string', ['limit' => 225, 'null' => true, 'default' => null, 'comment' => '参与商品'])
            ->addColumn(Column::enum('status', ['unpaid', 'paid'])->setDefault('unpaid')->setComment('状态:unpaid=未支付,paid=已支付'))
            ->addColumn('ext', 'string', ['limit' => 2048, 'null' => true, 'default' => null, 'comment' => '附加信息'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('activity_id')
            ->addIndex('order_id')
            ->addIndex('user_id')
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_activity_order');
        $table->drop();
    }
}
